<?php
  require_once '../../Helpers/DbHelper.php';
  require_once '../../Helpers/PathHelper.php';
  require_once '../../Controllers/UserController.php';
  //
  $u = new UserController();
  $u->evaluatePagePermission(UserController::ADMINISTRATOR);
  //
  require_once '../../Controllers/AdminController.php';
  require_once '../../Controllers/StudentController.php';
  require_once '../../Controllers/SchoolController.php';
  require_once '../../Controllers/EnrolmentController.php';
  //
	  $a = new AdminController();
    $yearLevelElem = $a->getYearLevelByDepartment(SchoolController::ELEMENTARY);
    //
	  $s = new StudentController();
	  $id = $_GET['id'];
	  $st = $s->read($id);
    //Process this area if the user has submitted the form for updates.
    if(isset($_POST) && !empty($_POST))
	  {
	    //Update student record.
      $c = new EnrolmentController();
      $message = $c->enrol(EnrolmentController::UPDATE);
  	  $st = $s->read($id);
	  }
	    //
	    $aStudent = mysql_fetch_assoc($st);
      //
	    $id = $aStudent['StudentId'];
	    $year = $aStudent['SchoolYear'];
	    $departmentId = $aStudent['DepartmentId'];
      $gradeLevel = $aStudent['GradeLevel'];
      $status = $aStudent['Status'];
	    //
	    $name = $aStudent['Name'];
	    $birthDate = $aStudent['BirthDate'];
	    $nickname = $aStudent['Nickname'];
	    $age = $aStudent['Age'];
	    $phoneNum = $aStudent['HomeNumber'];
	    $addr = $aStudent['Address'];
	    $religion = $aStudent['Religion'];
	    $nationality = $aStudent['Nationality'];
	    $gender = $aStudent['Sex'];
	    $schoolAttended = $aStudent['SchoolAttended'];
	    $schoolAttendedYr = $aStudent['SchoolYearAttended'];
      //
      $livesWith = $aStudent['LivesWith'];
      $livesWithSpecify = $aStudent['LivesWithSpecify'];
      //
      $father =  $aStudent['FathersName'];
      $fathersCel = $aStudent['FathersCellphone'];
      $fathersOccupation = $aStudent['FathersOccupation'];
      $fathersOfficePhone = $aStudent['FathersOfficeNumber'];
      $mother = $aStudent['MothersName'];
      $mothersCel = $aStudent['MothersCellphone'];
      $mothersOccupation = $aStudent['MothersCellphone'];
      $mothersOfficePhone = $aStudent['MothersOfficeNumber'];
      //
      $emergencyGuardianName1 = $aStudent['EmergencyGuardianName1'];
      $emergencyGuardianCel1 = $aStudent['EmergencyGuardianCellphone1'];
      $emergencyGuardianRelationship1 = $aStudent['EmergencyGuardianRelationShip1'];
      $emergencyGuardianName2 = $aStudent['EmergencyGuardianName2'];
      $emergencyGuardianCel2 = $aStudent['EmergencyGuardianCellphone2'];
      $emergencyGuardianRelationship2 = $aStudent['EmergencyGuardianRelationShip2'];
	    //
	    $hasAllergies = $aStudent['HasAllergies'];
	    $allergyDetails = $aStudent['AllergyDetails'];
	    $hasMedicalConditions = $aStudent['HasMedicalConditions'];
	    $hasMedicalConditionDetails = $aStudent['HasMedicalConditionDetails'];
	    $hasBehaviorIssues = $aStudent['HasBehaviorIssues'];
	    $hasBehaviorIssueDetails = $aStudent['HasBehaviorIssueDetails'];
	    $childInfoOthers = $aStudent['ChildInfoOthers'];


      $p = $a->readElementaryDetails($id);
      $pDetails = mysql_fetch_assoc($p);
      //
		  $parentsAbsenceReason = $pDetails['ParentsAbsenceReason'];
			$parentsAbsenceSpecify = $pDetails['ParentsAbsenceSpecify'];
			$takesCare = $pDetails['WhoTakesCare'];
			$takesCareSpecify = $pDetails['TakesCareSpecify'];
			$parentStatus = $pDetails['ParentStatus'];
			$parentsMarriageType = $pDetails['ParentsMarriageType'];
	  //
?>
<html>
  <title>School Enrollment :: Enrollment Form</title>
  <head>
    <link type="text/css" href="../../assets/styles.css" rel="stylesheet">
    <link type="text/css" href="../../assets/tabs.css" rel="stylesheet">
    <base href="../../" target="">
    <script type="text/javascript" src="assets/js/jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="../../assets/js/jquery-ui-1.8.16.custom.min.js"></script>
    <script type="text/javascript" src="../../assets/js/jquery.ui.tabs.js"></script>
    <script type="text/javascript">
      $(document).ready(function()
      {
      	//When page loads...
      	//$('.enrolment-form').hide();
        $('#enrolment-status-pre,#enrolment-status-elem').attr('checked', false);
      	$(".tab_content").hide(); //Hide all content
      	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
      	$(".tab_content:first").show(); //Show first tab content
        //On Open Enrolment
        $('#enrolment-status-pre').click(function()
        {
          $('#prelem').slideToggle();
        });
        $('#enrolment-status-elem').click(function()
        {
          $('#elem').slideToggle();
        });
      	$("ul.tabs li").click(function()
      	{
      		$("ul.tabs li").removeClass("active"); //Remove any "active" class
      		$(this).addClass("active"); //Add "active" class to selected tab
      		$(".tab_content").hide(); //Hide all tab content
      		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
      		$(activeTab).fadeIn(); //Fade in the active ID content
      		return false;
      	});
      });

    </script>
  </head>
  <body>
    <div class="container">
     <?php
        require_once '../commons.php';
        renderAdminNav();
      ?>
      <ul class="tabs">
          <li><a href="#tab1">Elementary</a></li>
      </ul>
      <div class="tab_container">
        <div id="tab2" class="tab_content">
            <!--Content-->
          <input type="radio" name="enrolment-status" id="enrolment-status-elem"/>Open Elementary Enrollment Form
          <?php if($message) {?><div align="center"><strong>STUDENT DETAILS SUCCESSFULLY UPDATED.</strong></div><?php } ?>
            <form name="enrolment-form" class="enrolment-form" id="elem" method="post" action="">
              <table cellpadding="0" align="center">
                <tr>
                  <th>ENROLLMENT FORM</th>
                </tr>
                <tr>
                  <td><label for="student-id">Student ID:</td>
                  <td><input type="text" name="student-id" value="<?php echo $id?>"/></td>
                </tr>
                <tr>
                  <td><label for="school-year">School Year:</label></td>
                  <td><input type="text" name="school-year" value="<?php echo $year?>"/></td>
                  <td><label for="grade">Grade:</label></td>
                  <td>
                    <select name="grade-level">
                      <?php
                       while($rows=mysql_fetch_assoc($yearLevelElem))
                        {
                          $content = "";
                          $content.='<option value="'.$rows['YearLevelId'].'"';
                          //
                          if($rows['YearLevelId'] == $gradeLevel)
                            $content.='selected';
                          //
                          $content.='>'.$rows['YearLevelDescription'].'</option>';
                          echo $content;
                        }
                      ?>
                    </select>
                  </td>
                </tr>
                <tr>
                  <td colspan="3">
                   <input type="radio" name="status" value="New" <?php if($status == 'New') echo 'checked'?> />New Student
                   <input type="radio" name="status" value="Old" <?php if($status == 'Old') echo 'checked'?>/>Old Student
                   <input type="radio" name="status" value="Returning" <?php if($status == 'Returning') echo 'checked'?>/>Returning Student
                  </td>
                  </tr>
                  <tr><td>&nbsp;</td></tr>
                  <tr>
                  <th colspan="2">STUDENT'S DETAILS</th>
                </tr>
               <tr>
                 <td><label for="name">Student's Name: </label></td>
                 <td><input type="text" name="name" value="<?php echo $name?>"/></td>
                 <td><label for="birth-date">Birth Date: </label></td>
                 <td><input type="text" name="birth-date" value="<?php echo $birthDate?>"></td>
               </tr>
               <tr>
                 <td><label for="nickname">Nickname: </label></td>
                 <td><input type="text" name="nickname" value="<?php echo $nickname?>"/></td>
                 <td><label for="age">Age:</label></td>
                 <td><input type="text" name="age" value="<?php echo $age?>"/></td>
               </tr>
                <tr>
                  <td><label for="home-number">Home Phone Number: </label></td>
                  <td><input type="text" name="home-number" value="<?php echo $phoneNum?>"/></td>
                  <td><label for="address">Address:</label></td>
                  <td><input type="text" name="address" value="<?php echo $addr?>"/></td>
                </tr>
                <tr>
                  <td><label for="religion">Religion:</label></td>
                  <td><input type="text" name="religion" value="<?php echo $religion?>"/></td>
                  <td><label for="nationality">Nationality:</label></td>
                  <td><input type="text" name="nationality" value="<?php echo $nationality?>"/></td>
                </tr>
                <tr>
                 <td><label for="sex">Sex: </label></td>
                 <td>
                   <input type="radio" name="sex" value="Male" <?php if($gender == 'Male') echo 'checked' ?> />Male
                   <input type="radio" name="sex" value="Female" <?php if($gender == 'Female') echo 'checked' ?>/>Female
                 </td>
                </tr>
                <tr>
                 <td><label for="school-attended">School attended (if transferee) <br />(if transferee): </label></td>
                 <td><input type="text" name="school-attended" value="<?php echo $schoolAttended?>" /></td>
                 <td><label for="school-year-attended">SY: </label></td>
                 <td><input type="text" name="school-year-attended" value="<?php echo $schoolAttendedYr?>"/></td>
                </tr>
                <tr>
                 <td><label for="lives-with">Student primarily lives with: </label></td>
                 <td colspan="2">
                   <input type="radio" name="lives-with" value="Both Parents" <?php if($livesWith == 'Both Parents') echo 'checked'?>/>Both Parents<br />
                   <input type="radio" name="lives-with" value="Mother only" <?php if($livesWith == 'Mother only') echo 'checked'?> />Mother only<br />
                   <input type="radio" name="lives-with" value="Father only" <?php if($livesWith == 'Father only') echo 'checked'?> />Father only <br />
                   <input type="radio" name="lives-with" value="Other" <?php if($livesWith == 'Other') echo 'checked'?> />Other <br />
                   <label for="lives-with-specify">Specify</label><input type="text" name="lives-with-specify" value="<?php echo $livesWithSpecify?>" />
                 </td>
                </tr>
		            <tr>
                  <td><label for="parents-absence-reason">If both parents are absent, please indicate the reasons of absence by checking one of the answers below: </label></td>
                 <td colspan="2">
                   <input type="radio" name="parents-absence-reason" value="Abroad" <?php if($parentsAbsenceReason == 'Abroad') echo 'checked'?> />Working Abroad<br />
                   <input type="radio" name="parents-absence-reason" value="Dead" <?php if($parentsAbsenceReason == 'Dead') echo 'checked'?>/>Mother or Father is dead<br />
                   <input type="radio" name="parents-absence-reason" value="Separated" <?php if($parentsAbsenceReason == 'Separated') echo 'checked'?>/>Mother and Father are separated<br />
                   <input type="radio" name="parents-absence-reason" value="Others" <?php if($parentsAbsenceReason == 'Others') echo 'checked'?>/>Others <br />
                   <label for="parents-absence-reason-specify">Specify: </label>
  			          <input type="text" name="parents-absence-reason-specify" value="<?php echo $parentsAbsenceSpecify?>" />
                 </td>
               </tr>
		           <tr>
                 <td><label for="takes-care">If both parents are absent, who takes care of the child? </label></td>
                 <td colspan="2">
                   <input type="radio" name="takes-care" value="Godparents-and-relatives" <?php if($takesCare == 'Godparents-and-relatives') echo 'checked'?>/>Godparents &amp; Relatives<br />
                   <input type="radio" name="takes-care" value="Orphan-house" <?php if($takesCare == 'Orphan-house') echo 'checked'?>/>Orphan House<br />
                   <input type="radio" name="takes-care" value="Older-siblings" <?php if($takesCare == 'Older-siblings') echo 'checked'?>/>Older Brother and / or Sister<br />
  			           <input type="radio" name="takes-care" value="Not-relatives" <?php if($takesCare == 'Not-relatives') echo 'checked'?> />Other people who are not Relatives<br />
                   <input type="radio" name="takes-care" value="Others" <?php if($takesCare == 'Others') echo 'checked'?> />Others <br />
                   <label for="takes-care-specify">Specify</label>
  			           <input type="text" name="takes-care-specify" value="<?php echo $takesCareSpecify?>"/>
                 </td>
               </tr>
               <tr>
                 <th colspan="2">PARENT'S DETAILS</th>
               </tr>
               <tr>
                 <td><label for="fathers-name">Father's Name: </label></td>
                 <td><input type="text" name="fathers-name"  value="<?php echo $father?>"/></td>
                 <td><label for="fathers-cellphone">Cellphone No.</label></td>
                 <td><input type="text" name="fathers-cellphone" value="<?php echo $fathersCel?>"/></td>
               </tr>
               <tr>
                 <td><label for="fathers-occupation">Occupation: </label></td>
                 <td><input type="text" name="fathers-occupation" value="<?php echo $fathersOccupation?>"/></td>
                 <td><label for="fathers-office-number">Office Phone No.</label></td>
                 <td><input type="text" name="fathers-office-number" value="<?php echo $fathersOfficePhone?>" /></td>
               </tr>
               <tr>
                 <td><label for="mothers-name">Mother's Name:</label></td>
                 <td><input type="text" name="mothers-name" value="<?php echo $mother?>"/></td>
                 <td><label for="mothers-cellphone">Cellphone No.</label></td>
                 <td><input type="text" name="mothers-cellphone" value="<?php echo $mothersCel?>" /></td>
               </tr>
             <tr>
               <td><label for="mothers-occupation">Occupation: </label></td>
               <td><input type="text" name="mothers-occupation" value="<?php echo $mothersOccupation?>" /></td>
               <td><label for="mothers-office-number">Office Phone No.</label></td>
               <td><input type="text" name="mothers-office-number" value="<?php echo $mothersOfficePhone?>"/></td>
             </tr>
             <tr>
               <td><label for="married-parents">Married: </label></td>
               <td colspan="2">
		             <input type="radio" name="married-parents" value="Married" <?php if($parentStatus == 'Married') echo 'checked'?>/>Yes
                 <input type="radio" name="married-parents" value="Not-married" <?php if($parentStatus == 'Not-married') echo 'checked'?> />No
                </td>
              </tr>
              <tr>
		            <td><label for="married">If yes, where?: </label></td>
		            <td colspan="2">
		              <input type="radio" name="parents-marriage-type" value="Church"  <?php if($parentsMarriageType == 'Church') echo 'checked'?>/>Catholic Church
                  <input type="radio" name="parents-marriage-type" value="Civil" <?php if($parentsMarriageType == 'Civil') echo 'checked'?>/>Civil Marriage
                </td>
             </tr>
             <tr>
               <td colspan="4">
                 <h3><strong>EMERGENCY CONTACTS</strong></h3><br />
                 <em>The emergency contact person must be somebody other than the parents.</em>
               </td>
             </tr>
             <tr>
               <td><label for="emergency-guardian-name[]">1. Name:</label></td>
               <td><input type="text" name="emergency-guardian-name[]" value="<?php echo $emergencyGuardianName1?>"/></td>
               <td><label for="emergency-guardian-cellphone[]">Home/Cellphone No.</label></td>
               <td><input type="text" name="emergency-guardian-cellphone[]" value="<?php echo $emergencyGuardianCel1?>"/></td>
             </tr>
             <tr>
               <td><label for="emergency-guardian-relationship[]">Relationship to child:</label></td>
               <td><input type="text" name="emergency-guardian-relationship[]" value="<?php echo $emergencyGuardianRelationship1?>"/></td>
             </tr>
             <tr>
               <td><label for="emergency-guardian-name[]">2. Name:</label></td>
               <td><input type="text" name="emergency-guardian-name[]" value="<?php echo $emergencyGuardianName2?>"/></td>
               <td><label for="emergency-guardian-cellphone[]">Home/Cellphone No.</label></td>
               <td><input type="text" name="emergency-guardian-cellphone[]" value="<?php echo $emergencyGuardianCel2?>"/></td>
             </tr>
             <tr>
               <td><label for="emergency-guardian-relationship[]">Relationship to child:</label></td>
               <td><input type="text" name="emergency-guardian-relationship[]" value="<?php echo $emergencyGuardianRelationship2?>"/></td>
             </tr>
             <tr>
               <td colspan="4"><h3><strong>GENERAL INFORMATION ABOUT YOUR CHILD</strong></h3></td>
             </tr>
             <tr>
               <td colspan="2"><label for="child-allergies">Does your child have any allergies?</label></td>
               <td>
                 <input type="radio" name="has-allergies" value="Yes" <?php if($hasAllergies == 'Yes') echo 'checked'?>/>Yes
                 <input type="radio" name="has-allergies" value="No"  <?php if($hasAllergies == 'No') echo 'checked'?>/>No
               </td>
             </tr>
             <tr>
               <td colspan="4"><p>If YES, please provide a detailed explanation of signs,symptoms and treatment needed.</p></td>
             </tr>
             <tr><td colspan="3"><textarea name="allergy-details" cols="40" rows="10"><?php echo $allergyDetails?></textarea></td>
             </tr>
             <tr>
               <td colspan="2"><label for="child-medical-condition">Does your child have any medical condition/impairment/disability that you feel we need to know about?</label></td>
               <td>
                 <input type="radio" name="has-medical-conditions" value="Yes" <?php if($hasMedicalConditions == 'Yes') echo 'checked'?>/>Yes
                 <input type="radio" name="has-medical-conditions" value="No"  <?php if($hasMedicalConditions == 'No') echo 'checked'?>/>No
               </td>
             </tr>
             <tr>
               <td colspan="4"><p>If YES - please provide a detailed explanation of what it is for and if there are any details our staff should know in order to provide care for your child and special understanding where needed.</p></td>
             </tr>
             <tr><td colspan="3"><textarea name="has-medical-condition-details" cols="40" rows="10"><?php echo $hasMedicalConditions?></textarea></td></tr>
             <tr>
               <td colspan="2"><label for="child-behavior-issues">Does your child have behavior management issues?</label><br />
                <em> (Example - ADHD, fears or phobias, non-responsive, uncooperative etc.)</em>
                 </td>
               <td>
                 <input type="radio" name="has-behavior-issues"  <?php if($hasBehaviorIssues == 'Yes') echo 'checked'?> value="Yes"/>Yes
                 <input type="radio" name="has-behavior-issues" value="No"  <?php if($hasBehaviorIssues == 'No') echo 'checked'?> />No
               </td>
             </tr>
             <tr>
               <td colspan="4"><p>If YES - please specify what medical condition, who it was diagnosed by, how it affects your child and management plans are in place including medication.</p></td>
             </tr>
             <tr><td colspan="3"><textarea name="has-behavior-issues-details" cols="40" rows="10"><?php echo $hasBehaviorIssueDetails ?></textarea></td></tr>
             <tr>
               <td colspan="4"><p>What other information(s) regarding your child that you feel our staff should be aware of?</p></td>
             </tr>
             <tr>
               <td colspan="3"><textarea name="child-info-others" rows="10" cols="40"><?php echo $childInfoOthers?></textarea></td>
             </tr>
             <tr>
               <td><input type="submit" name="elem-form" value="Save Form Details" /></td>
             </tr>
           </table>
         </form>
        </div>
        <a id="prev-next" href="<?php echo PathHelper::getBaseUrl().'/Views/Admin/input_fees.php?id='.$id?>">Next Step &rarr;</a>
    </div><!--end of tab container -->
    </div><!--end of container -->
  </body>
</html>
